package com.gen;

import java.io.File;
import java.io.IOException;
import java.util.HashMap;
import java.util.Map;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.SAXException;

public class Start {

	public static void main(String[] args) throws ParserConfigurationException, SAXException, IOException {
		File f=new File("D:\\workspace\\edu-java-api\\edu-mobile-api\\src\\main\\resources\\mybatis");
		if(f.exists()){
			File[] flist=f.listFiles();
			Node node;
			NamedNodeMap nnm;
			Map<String, String> map=new HashMap<String, String>();
			String content="package com.edu.dao\n";
			for(int i=0;i<flist.length;i++){
				DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); 
				DocumentBuilder db = dbf.newDocumentBuilder();  
		        Document document = db.parse(flist[i]);
		        NodeList mapper = document.getElementsByTagName("mapper");
		        NodeList select = document.getElementsByTagName("select");
		        NodeList update = document.getElementsByTagName("update");
		        String namespace="";
		        for (int j = 0; j < mapper.getLength(); j++) {
					node=mapper.item(j);
					nnm=node.getAttributes();
					namespace=nnm.getNamedItem("namespace").getTextContent();
		        }
		        content+=namespace.substring(0,namespace.lastIndexOf("."));
		        content+=
		        for (int j = 0; j < select.getLength(); j++) {
		        	node=select.item(j);
					nnm=node.getAttributes();
					System.out.println(nnm.getNamedItem("id").getTextContent()+"===from=="+namespace);
				}
		        System.out.println(content);
		        content="package com.edu.dao\n";
			}
		}else{
			System.out.println("文件不存在");
		}
	}

}
